package cn.ijero.contactlist.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import cn.ijero.contactlist.database.dao.ContactDao
import cn.ijero.contactlist.database.table.Contact

@Database(entities = [Contact::class], version = 1)
abstract class AppDatabase : RoomDatabase() {

    companion object {
        fun create(context: Context): AppDatabase {
            return Room.databaseBuilder(
                context.applicationContext,
                AppDatabase::class.java,
                "app.db"
            ).build()
        }
    }

    abstract fun contactDao(): ContactDao
}

val Context.database: AppDatabase
    get() = AppDatabase.create(this)